﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 每个Creature都有一个CD管理器
public class CDMgr
{
    // 公共CD
    CD _commonCD = new CD();

    public CDMgr()
    {
        _commonCD.MaxCD = 1f;
    }

    public bool IsInCD(CD cd)
    {
        return _commonCD.IsInCD || cd.IsInCD;
    }

    public float LeftCD(CD cd)
    {

        return Mathf.Max(_commonCD.LeftCD, cd.LeftCD);
    }

    public float MaxCD(CD cd)
    {
        if (cd.LeftCD > _commonCD.LeftCD)
        {
            return cd.MaxCD;
        }

        return _commonCD.MaxCD;
    }

    public void Start(CD cd)
    {
        cd.Start();
        _commonCD.Start();
    }
}

// 技能CD
public class CD
{
    public float MaxCD; // 最大CD
    private float _startTime = float.MinValue; // 开始时间戳

    // 是否处于CD中
    public bool IsInCD { get { return LeftCD > 0 ; } }

    public float LeftCD { get
        {
            return Mathf.Max(0, MaxCD - (Time.time - _startTime));
        }
    }

    public void Start()
    {
        _startTime = Time.time;
    }
}
